/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Session;

import Entity.Client;
import Entity.Courtier;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author guillaumediliberatore
 */
@Stateless
public class CourtierSession implements CourtierSessionLocal {


        @javax.persistence.PersistenceContext(unitName = "Assurance-ejbPU")
    private EntityManager em;
    
    
    public boolean connexion(String login, String pwd){
        System.out.println("Test1");
        if(login != null && pwd != null) {
            System.out.println("Test2");
            //Client c = (Client) em.createNamedQuery("Client.findAll").getSingleResult();
            Query test = em.createNamedQuery("Courtier.findByLogincourtier");
            System.out.println("Test3");
            test.setParameter("logincourtier",  login) ;
            System.out.println("Test4");
            Courtier c = (Courtier) test.getSingleResult() ;
            System.out.println("Test5");
            
            if(c.getLogincourtier().equals(login) && c.getMotdepassecourtier().equals(pwd)) {
               
                System.out.println("Test4");
                return true;
            }
            
        }
        return false;
        
    }
    
    @Override
    public Courtier getCourtier(String pseudo){
        Query q = em.createNamedQuery("Courtier.findByLogincourtier"); 
        q.setParameter("logincourtier", pseudo);
        Courtier c = (Courtier) q.getSingleResult();
        return c;
        
    }
    
}
